package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbFreight;
import com.ruoyi.system.service.ITbFreightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运费Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/freight")
public class TbFreightController extends BaseController
{
    @Autowired
    private ITbFreightService tbFreightService;

    /**
     * 查询运费列表
     */
    @PreAuthorize("@ss.hasPermi('system:freight:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbFreight tbFreight)
    {
        startPage();
        List<TbFreight> list = tbFreightService.selectTbFreightList(tbFreight);
        return getDataTable(list);
    }

    /**
     * 导出运费列表
     */
    @PreAuthorize("@ss.hasPermi('system:freight:export')")
    @Log(title = "运费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbFreight tbFreight)
    {
        List<TbFreight> list = tbFreightService.selectTbFreightList(tbFreight);
        ExcelUtil<TbFreight> util = new ExcelUtil<TbFreight>(TbFreight.class);
        util.exportExcel(response, list, "运费数据");
    }

    /**
     * 获取运费详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:freight:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbFreightService.selectTbFreightById(id));
    }

    /**
     * 新增运费
     */
    @PreAuthorize("@ss.hasPermi('system:freight:add')")
    @Log(title = "运费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbFreight tbFreight)
    {
        return toAjax(tbFreightService.insertTbFreight(tbFreight));
    }

    /**
     * 修改运费
     */
    @PreAuthorize("@ss.hasPermi('system:freight:edit')")
    @Log(title = "运费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbFreight tbFreight)
    {
        return toAjax(tbFreightService.updateTbFreight(tbFreight));
    }

    /**
     * 删除运费
     */
    @PreAuthorize("@ss.hasPermi('system:freight:remove')")
    @Log(title = "运费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbFreightService.deleteTbFreightByIds(ids));
    }
}
